package com.xxx.modules.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xxx.modules.mapper.HouseMapper;
import com.xxx.modules.entity.House;
import com.xxx.modules.service.HouseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.util.List;
import java.util.Arrays;
import com.xxx.modules.utils.TimeUtil;

/**
 * house
 *
 * @author 北易航
 * @since 1.0.0 2022-12-28
 */
@Service
public class HouseServiceImpl extends ServiceImpl<HouseMapper, House> implements HouseService {

    @Autowired
    private HouseMapper houseMapper;


    @Override
    public PageInfo<House> selectHouseInfo(House house, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<House> wrapper = new QueryWrapper<>();
        if (house.getRoomNumber() !=null){
            wrapper.like("room_number",house.getRoomNumber());
        }
//        if (house.getRealName() !=null){
//            wrapper.like("real_name",house.getRealName());
//        }
        List<House> data = houseMapper.getHousesByOldId(wrapper);
        return new PageInfo<>(data);
    }

    @Override
    public void saveHouseInfo(House house) {
        house.setCreateTime(TimeUtil.getCurrentTime());
        houseMapper.insert(house);
    }

    @Override
    public void updateHouseInfo(House house) {
        houseMapper.updateById(house);
    }

    @Override
    public void delHouseInfo(Integer id) {
        houseMapper.deleteById(id);
    }

    @Override
    public void delBatchHouseInfo(String idList) {
        List<String> list = Arrays.asList(idList.split(","));
        houseMapper.deleteBatchIds(list);
    }


}